import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const library = new Vuex.Store({
  state: {
    token:""
  },
  mutations: {
    setToken(state,value){
      state.token = value
    }
  },
  actions: {
  },
  modules: {
  }
})

// vuex 页面刷新 数据丢失 解决方案
window.addEventListener("beforeunload", () => {
  localStorage.setItem("stateInfo", JSON.stringify(library.state));
});

if (localStorage.getItem("stateInfo")) {
  library.replaceState(
    Object.assign(
      {},
      library.state,
      JSON.parse(localStorage.getItem("stateInfo"))
    )
  );
}

localStorage.removeItem("stateInfo");


export default library